package logic

import (
	"context"
	"github.com/pkg/errors"
	"mall/app/product/cmd/rpc/product"
	"mall/common/xerr"

	"mall/app/product/cmd/api/internal/svc"
	"mall/app/product/cmd/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteCategoryBatchLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeleteCategoryBatchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteCategoryBatchLogic {
	return &DeleteCategoryBatchLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteCategoryBatchLogic) DeleteCategoryBatch(req *types.DeleteCategoryBatchReq) (err error) {
	list := req.CatIdList
	_, err = l.svcCtx.ProductRpc.DeleteCategoryBatch(l.ctx, &product.DeleteCategoryBatchReq{CatIdList: list})
	if err != nil {
		return errors.Wrapf(xerr.NewErrorWithMsg("删除失败"), "err: %v req: %+v", err, req)
	}
	return nil
}
